package pt.nmfa.peste.session;

import pt.nmfa.peste.entity.*;
import java.util.ArrayList;
import java.util.List;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.framework.EntityHome;

@Name("statusActionsHome")
public class StatusActionsHome extends EntityHome<StatusActions> {

	@In(create = true)
	DeviceHome deviceHome;

	public void setStatusActionsStatusActionId(Integer id) {
		setId(id);
	}

	public Integer getStatusActionsStatusActionId() {
		return (Integer) getId();
	}

	@Override
	protected StatusActions createInstance() {
		StatusActions statusActions = new StatusActions();
		return statusActions;
	}

	public void load() {
		if (isIdDefined()) {
			wire();
		}
	}

	public void wire() {
		getInstance();
		Device device = deviceHome.getDefinedInstance();
		if (device != null) {
			getInstance().setDevice(device);
		}
	}

	public boolean isWired() {
		if (getInstance().getDevice() == null)
			return false;
		return true;
	}

	public StatusActions getDefinedInstance() {
		return isIdDefined() ? getInstance() : null;
	}

	public List<StatusActionsScript> getStatusActionsScripts() {
		return getInstance() == null ? null
				: new ArrayList<StatusActionsScript>(getInstance()
						.getStatusActionsScripts());
	}

}
